package org.saber.geo.utils;

import java.util.ArrayList;
import java.util.List;

import org.saber.geo.model.Point;


/**
 * 多边形工具
 * @author saber
 *
 */
public class PolygonUtils {

	private static PolygonUtils polygonUtils;
	
	public static PolygonUtils getInstance() {
		if(polygonUtils==null)
			polygonUtils=new PolygonUtils();
		return polygonUtils;
	}
	
	/**
	 * 多边形缩放
	 * @param oriPointList
	 * @param scaling 缩放倍率
	 * @return
	 */
	public List<Point> getTransPointList(List<Point> oriPointList, double scaling){
//		List<Point> pointList=new ArrayList<Point>();
//		
//		String path="117.187049,39.130323;117.182929,39.123998;117.196748,39.117539;117.201469,39.124065;117.192628,39.128526";
//		
//		String pathS="117.163789,39.134501;117.188852,39.130839;117.168596,39.130174;117.187478,39.126179;117.186105,39.115125;117.160098,39.117522;117.180011,39.118854;117.164647,39.130107;117.159841,39.132038";
//		String[] pathArr=pathS.split(";");
//		
//		for (String pointStr : pathArr) {
//			String[] pointArr=pointStr.split(",");
//			pointList.add(new Point(Double.valueOf(pointArr[0]),Double.valueOf(pointArr[1])));
//		}
		
		List<Point> subPointList=new ArrayList<>();
		//使用重心点作为中心点
		Point pointCenter=PlaneCoordinateUtils.getCenterOfGravityPoint(oriPointList);
		for (Point oriPoint : oriPointList) {
			
			Location location=PlaneCoordinateUtils.checkLocation(pointCenter, oriPoint);
			
			Point ss=PlaneCoordinateUtils.getPoint(pointCenter,PlaneCoordinateUtils.getDistance(pointCenter, oriPoint)*scaling,
					PlaneCoordinateUtils.getK(pointCenter, oriPoint), location);
			
			subPointList.add(ss);
		}
		
		return subPointList;
	}

	/**
	 * 检测坐标点是否在中心点左侧
	 * @param centerPoint
	 * @param oriPoint
	 * @return
	 */
	@Deprecated
	public boolean isLeftCheck(Point basePoint,Point oriPoint) {
		if(basePoint.getX()>=oriPoint.getX()) {
			return true;
		}
		return false;
		
		
	}
	
	
	
	
	
}
